{% extends 'crm/dashboard_template.html' %}

{% block title %}
    <title>导航模板</title>
{% endblock %}

{% block project_name %}
    <a class="navbar-brand" href="#">LowCRM</a>
{% endblock %}

{% block navebar %}
    <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Dashboard</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ request.user.userprofile }}<span class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a href="/logout/">注销</a></li>
                </ul>
            </li>
            <li><a href="#">Help</a></li>
        </ul>
        <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search...">
        </form>
    </div>
{% endblock %}

{% block sidebar %}
    <div class="col-sm-3 col-md-2 sidebar">
        {% for role in request.user.userprofile.roles.all %}
            <p>角色：{{ role.name }}</p>
            <ul class="nav nav-sidebar">
            {% for menu in role.menus.all %}
                {% if menu.url_type == 0 %}
                <li><a href="{% url 'crm:'|add:menu.url_name %}">{{ menu.name }}</a></li>
                {% else %}
                <li><a href="{{ menu.url_name }}">{{ menu.name }}</a></li>
                {% endif %}
            {% endfor %}
            </ul>
        {% endfor %}
    </div>
{% endblock %}

{% block js %}
    <script>
        // 左侧边栏，鼠标悬停效果
        $('div.sidebar li').hover(
            function () {
                $(this).addClass('active')
            },
            function () {
                $(this).removeClass('active')
            }
        );

        // 左侧边栏，当前页面标记
        $(function () {
            $('div.sidebar li>a[href="{{ request.path }}"]').text(function (index, text) {
                return text+' >>'
            })
        })
    </script>
{% endblock %}

